import {
  GetVerifyCode,
  GuestBindMobilePhoneParams,
  GuestLoginParams,
  Login,
  LoginWithPassword,
  LoginWithVerifyCode,
  RefreshToken
} from './paramsInterface';
import request from '../request';
import { LoginRes } from './login';
import {
  LOGOUT_REQ,
  GET_VERIFY_CODE_REQ,
  LOGIN_WITH_VERIFY_CODE_REQ,
  LOGIN_WITH_PASSWD_REQ,
  REFRESH_TOKEN_REQ,
  GUEST_LOGIN_REQ,
  GUEST_BIND_MOBILE_PHONE_REQ
} from '../../service/constant';
import { CommonRes } from '../commonRes';
import { GetVerifyCodeRes } from './getVerifyCode';
import { RefreshTokenRes } from './refreshToken';

export default {
  // 获取验证码
  getVerifyCode: (data: GetVerifyCode): Promise<GetVerifyCodeRes> =>
    request({
      msgId: GET_VERIFY_CODE_REQ,
      data,
      param: { needUserId: false, needLoading: true }
    }),
  // 使用手机号和验证码登录
  loginWithVerifyCode: (data: LoginWithVerifyCode): Promise<LoginRes> =>
    request({
      msgId: LOGIN_WITH_VERIFY_CODE_REQ,
      data,
      param: { needUserId: false, needLoading: true }
    }),
  // 使用手机号和密码登录
  loginWithPassword: (data: LoginWithPassword): Promise<LoginRes> =>
    request({
      msgId: LOGIN_WITH_PASSWD_REQ,
      data,
      param: { needUserId: false, needLoading: true }
    }),
  // 刷新token
  refreshToken: (data: RefreshToken): Promise<RefreshTokenRes> =>
    request({
      msgId: REFRESH_TOKEN_REQ,
      data,
      param: { needUserId: true }
    }),
  // 退出登录
  logout: (): Promise<CommonRes> =>
    request({
      msgId: LOGOUT_REQ,
      param: { needUserId: true, needLoading: true }
    }),
  // 游客登录
  guestLogin: (data: GuestLoginParams): Promise<LoginRes> =>
    request({
      msgId: GUEST_LOGIN_REQ,
      data,
      param: { needLoading: true }
    }),
  // 游客绑定手机号
  guestBindMobilePhone: (data: GuestBindMobilePhoneParams): Promise<LoginRes> =>
    request({
      msgId: GUEST_BIND_MOBILE_PHONE_REQ,
      data,
      param: { needLoading: true }
    })
};
